package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.TProfitBillInfo;
import com.ruoyi.finance.service.ITProfitBillInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 利润账单Controller
 * 
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/finance/profit")
public class TProfitBillInfoController extends BaseController
{
    @Autowired
    private ITProfitBillInfoService tProfitBillInfoService;

    /**
     * 查询利润账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProfitBillInfo tProfitBillInfo)
    {
        startPage();
        List<TProfitBillInfo> list = tProfitBillInfoService.selectTProfitBillInfoList(tProfitBillInfo);
        return getDataTable(list);
    }

    /**
     * 导出利润账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:export')")
    @Log(title = "利润账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProfitBillInfo tProfitBillInfo)
    {
        List<TProfitBillInfo> list = tProfitBillInfoService.selectTProfitBillInfoList(tProfitBillInfo);
        ExcelUtil<TProfitBillInfo> util = new ExcelUtil<TProfitBillInfo>(TProfitBillInfo.class);
        util.exportExcel(response, list, "利润账单数据");
    }

    /**
     * 获取利润账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:query')")
    @GetMapping(value = "/{profitBillId}")
    public AjaxResult getInfo(@PathVariable("profitBillId") Long profitBillId)
    {
        return success(tProfitBillInfoService.selectTProfitBillInfoByProfitBillId(profitBillId));
    }

    /**
     * 新增利润账单
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:add')")
    @Log(title = "利润账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProfitBillInfo tProfitBillInfo)
    {
        tProfitBillInfo.setCreateBy(getNickName());
        return toAjax(tProfitBillInfoService.insertTProfitBillInfo(tProfitBillInfo));
    }

    /**
     * 修改利润账单
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:edit')")
    @Log(title = "利润账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProfitBillInfo tProfitBillInfo)
    {
        tProfitBillInfo.setUpdateBy(getNickName());
        return toAjax(tProfitBillInfoService.updateTProfitBillInfo(tProfitBillInfo));
    }

    /**
     * 删除利润账单
     */
    @PreAuthorize("@ss.hasPermi('finance:profit:remove')")
    @Log(title = "利润账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{profitBillIds}")
    public AjaxResult remove(@PathVariable Long[] profitBillIds)
    {
        return toAjax(tProfitBillInfoService.deleteTProfitBillInfoByProfitBillIds(profitBillIds));
    }
}
